package org.csu.storemanage.service;


import org.csu.storemanage.mapper.ItemMapper;
import org.csu.storemanage.pojo.Item;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

@Service
public class ItemService {
    //商品管理服务
    @Autowired
    private ItemMapper itemMapper;

    public List<Item> getItemListByProductId(@Param("productId") String productId){
        return itemMapper.getItemListByProductId(productId);
    }

    public Item getItem(@Param("itemId") int itemId){
        return itemMapper.getItem(itemId);
    }

    public void addItem(@Param("categoryId")String categoryId, @Param("name")String name, @Param("quantity")int quantity,
                        @Param("unitPrice")BigDecimal unitPrice,@Param("description")String description,@Param("state")String state,@Param("limit")String limit){
        itemMapper.addItem(categoryId, name, quantity, unitPrice, description, state, limit);
    }

    public void editItem(@Param("oldName")String oldName, @Param("quantity")int quantity,
                         @Param("description")String description,@Param("state")String state,@Param("limit")String limit,@Param("newName") String newName,@Param("unitPrice")BigDecimal unitPrice){
        itemMapper.editItem(oldName, quantity, description, state, limit,newName,unitPrice);
    }

    public void deleteItem(@Param("itemId")int itemId){
        itemMapper.deleteItem(itemId);
    }

    public List<Item> getItemList(){
        return itemMapper.getItemList();
    }

    public List<Item> getItemListByCategoryId(@Param("categoryId")String categoryId){
        return itemMapper.getItemListByCategoryId(categoryId);
    }

    public void deleteCategory(@Param("categoryId")String categoryId){itemMapper.deleteCategory(categoryId);}

    public void deleteItemByName(@Param("itemName")String itemName){itemMapper.deleteItemByName(itemName);}
}
